package com.liumapp.auth.zuul.token.conf;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore;

/**
 * 资源服务器
 * 
 * @author sunshine
 * 
 */
@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

	private static final String RESOURCE_ID = "service-rest-api";

	@Autowired
	private TokenStore tokenStore;

	@Override
	public void configure(ResourceServerSecurityConfigurer resources) {
		resources.resourceId(RESOURCE_ID).tokenStore(tokenStore).stateless(true);
	}

	@Override
	public void configure(HttpSecurity http) throws Exception {
//		super.configure(http);

//		http.authorizeRequests().antMatchers("/doc*/**").authenticated().and().httpBasic();

		http
			.authorizeRequests()
//				.antMatchers("/webjars*/**").permitAll()
//				.antMatchers("doc*/**","/swagger-ui.html").authenticated()
//			.and()
//				.httpBasic()
			.and()
				.authorizeRequests().anyRequest().authenticated();

	}

}